package com.example.cmh.common;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;

public class DeleteUtil {

    // OSS配置信息
    private static final String ENDPOINT = "oss-cn-beijing.aliyuncs.com"; // 替换为您的OSS Endpoint
    private static final String ACCESS_KEY_ID = "LTAI5tBUGLbsnbK8D9dHCaaR"; // 替换为您的AccessKeyId
    private static final String ACCESS_KEY_SECRET = "xzd66dEwwM3xIk715QBpicMkQTzXMe"; // 替换为您的AccessKeySecret
    private static final String BUCKET_NAME = "cmh-springboot-vue3"; // 替换为您的Bucket名称

    /**
     * 删除OSS中的单个文件
     *
     * @param objectName 要删除的文件名（可以包含路径，例如 "folder/filename.ext"）
     */
    public static void deleteFile(String objectName) {
        OSS ossClient = null;
            ossClient = new OSSClientBuilder().build(ENDPOINT, ACCESS_KEY_ID, ACCESS_KEY_SECRET);

            ossClient.deleteObject(BUCKET_NAME, objectName);
            System.out.println("文件删除成功: " + objectName);


           ossClient.shutdown();
    }

}